﻿function openForm(action, id, archInfoId) {
    var result = window.open("ZHArchForm.aspx?id=" + id + "&action=" + action + "&archInfoId=" + archInfoId);
    if (result == "ok") {
        window.location.reload();
    }
}

function deleteConfirm() {
    if (confirm('确定要删除该条记录？')) {
        return true;
    }
    return false;
}

function listSearch() {
    $(ClientIds.btnSearch)[0].click();
}

//服务端控件ID获取
var ClientIds = getClientIds();

function uploadTemplate() {
    var template = "/Resources/Templates/综合资料信息导入模板.xls";

    var fileInfo = OpenFileUploaderWithFile("批量导入模板", template);
//    var fileInfo = 'file;file';

    if (fileInfo) {
        jQuery.ajax({
            url: "/Common/Services/BaseInfoFormHandler.aspx",
            type: "POST",
            dataType: "text",
            data: {
                method: 'UploadZHArchInfos',
                file: fileInfo
            },
            success: function (result) {
                if (result == 'ok') {
                    alert('操作成功！');
                    listSearch();
                } else {
                    $("#messageContent").html(result);
                    $('#returnMessage').dialog('open');
                    //alert('操作失败！请联系管理员。错误原因：' + result);
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert('系统错误 status:' + xmlHttpRequest.status + ' readyState:' + xmlHttpRequest.readyState + ' textStatus:' + textStatus);
            }
        });
    }
}

function uploadFile(archInfoId) {
    var result = window.showModalDialog("FileUploader.aspx?archInfoId=" + archInfoId, self, "dialogheight: 450px; dialogwidth: 620px; center:yes; resizable:yes; scroll:no; status:no;");
    if (result == "ok") {
        //listSearch();
    }
}

function CheckChange(obj) {
    if ($(obj).parent().attr('class') == 'checkboxGroup1') {
        $('.checkboxGroup2').find('input').attr('checked', false);
        if ($('.checkboxGroup1').find('input').attr('checked')) {
            $("._selectItem").each(function() {
                $(this).attr("checked", true);
            });
        } else {
            $("._selectItem").each(function() {
                $(this).attr("checked", false);
            });
        }
    } else
        if ($(obj).parent().attr('class') == 'checkboxGroup2') {
        $('.checkboxGroup1').find('input').attr('checked', false);
        if ($('.checkboxGroup2').find('input').attr('checked')) {
            $("._selectItem").each(function() {
                $(this).attr("checked", true);
            });
        } else {
            $("._selectItem").each(function() {
                $(this).attr("checked", false);
            });
        }
    }
}

//销毁资料
function destory() {
    var selectItemsInfo = GetSelectedItem();
    if (selectItemsInfo == "") {
        alert('未选择任何记录，请先选择。');
        return;
    }
    if (confirm('确认要将所选资料信息销毁？')) {
        jQuery.ajax({
            url: "/Common/Services/BaseInfoFormHandler.aspx",
            type: "POST",
            dataType: "text",
            data: {
                method: 'DestoryArchInfos',
                ids: selectItemsInfo
            },
            success: function (result) {
                if (result == 'ok') {
                    alert('操作成功！');
                    listSearch();
                } else {
                    alert('操作失败！请联系管理员。错误原因：' + result);
                }

            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert('系统错误 status:' + xmlHttpRequest.status + ' readyState:' + xmlHttpRequest.readyState + ' textStatus:' + textStatus);
            }
        });
    }
}

//获得所选信息
//返回格式：id1,id2,id3
function GetSelectedItem() {
    var selectedItems = "";
    $("input[type='checkbox']").each(function () {
        if (this.id == 'chkHeader' || this.id == 'MainHolder_CurrentPage') {
            return true;
        }
        if ($(this).attr("checked") && $(this).attr('class') == '_selectItem') {
            selectedItems += $(this).val() + ",";
        }
    });
    if (selectedItems != "")
        selectedItems = selectedItems.substr(0, selectedItems.length - 1);
    return selectedItems;
}

function exportData() {
    $(ClientIds.exportBtn)[0].click();
}